<?php

declare(strict_types=1);

namespace App\Api\Controller;

use App\Api\Middleware\ApiLockMiddleware;
use App\Api\Middleware\CheckAuthMiddleware;
use App\Api\Middleware\ResponseMiddleware;
use App\Api\Request\MemberRequest;
use App\Api\Service\MemberService;
use App\Model\Member;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\PutMapping;

#[Controller(prefix: 'api'), Middlewares([ResponseMiddleware::class])]
class MemberController
{
    /**
     * 获取用户信息
     * @param MemberService $service
     * @return Member
     */
    #[GetMapping('personal'), Middlewares([CheckAuthMiddleware::class])]
    public function index(MemberService $service): Member
    {
        return $service->index();
    }

    /**
     * 更新用户信息
     * @param MemberRequest $request
     * @param MemberService $service
     * @return void
     */
    #[PutMapping('personal'), Middlewares([CheckAuthMiddleware::class, ApiLockMiddleware::class])]
    public function update(MemberRequest $request, MemberService $service): void
    {
        $service->update($request->validated());
    }
}
